package com.cays.myresearch.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;

import com.cays.myresearch.R;
import com.cays.myresearch.constant.Constant;
import com.cays.myresearch.ui.HeadControlPanel;

public class RegisterActivity extends AppCompatActivity implements
    HeadControlPanel.HeadPanelCallback,View.OnClickListener{
    private HeadControlPanel registerHeader;
    private EditText registerUserName;
    private EditText registerUserPassword1;
    private EditText registerUserPassword2;
    private RadioGroup registerCheckType;
    private Button registerSubmit;
    private Button registerCancel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        if (getSupportActionBar()!=null){getSupportActionBar().hide();}
        if(registerHeader==null){
            registerHeader=(HeadControlPanel)findViewById(R.id.register_header);
            registerHeader.initHeadPanel();
            registerHeader.setHeadPanelCallback(this);
        }
        registerHeader.setLeftImage(R.drawable.ic_back);
        registerHeader.setMiddleTitle("注册");
        registerHeader.setRightTitle("");
        initView();
    }
    private void initView(){
        registerUserName = (EditText) findViewById(R.id.register_user_name);
        registerUserPassword1 = (EditText) findViewById(R.id.register_user_password1);
        registerUserPassword2 = (EditText) findViewById(R.id.register_user_password2);
        registerCheckType = (RadioGroup) findViewById(R.id.register_check_type);
        registerSubmit = (Button) findViewById(R.id.register_submit);
        registerSubmit.setOnClickListener(this);
        registerCancel = (Button) findViewById(R.id.register_cancel);
        registerCancel.setOnClickListener(this);
    }
    @Override
    public void onHeadPanelClick(int itemId) {
        switch (itemId){
            case Constant.btn_left_title:
                finish();
                break;
            case Constant.btn_middle_title:
                break;
            case Constant.btn_right_title:
                break;
            default:break;
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.register_submit:registerUserInfo();break;
            case R.id.register_cancel:finish();break;
            default:break;
        }
    }
    private void registerUserInfo(){
        String name=registerUserName.getText().toString();
        String password1=registerUserPassword1.getText().toString();
        String password2=registerUserPassword2.getText().toString();
        int type=0,radioId=registerCheckType.getCheckedRadioButtonId();
        if(radioId==R.id.login_check_student)type= Constant.user_student;
        else if(radioId==R.id.login_check_teacher)type= Constant.user_teacher;
        else if(radioId==R.id.login_check_staff)type= Constant.user_staff;

    }
}
